/**
 * 车次线路管理管理初始化
 */
var ScheduleStation = {
    id: "ScheduleStationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ScheduleStation.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '引用的车站id', field: 'stationId', visible: false, align: 'center', valign: 'middle'},
        {title: '调度车_id', field: 'staId', visible: false, align: 'center', valign: 'middle'},
        {title: '序号', field: 'seq', visible: true, align: 'center', valign: 'middle'},
        {title: '站点名称', field: 'stationName', visible: true, align: 'center', valign: 'middle'},
        {title: '到站时间', field: 'arrTime', visible: true, align: 'center', valign: 'middle'},
        {title: '发车时间', field: 'startTime', visible: true, align: 'center', valign: 'middle'},
        {title: '停留时间(分钟)', field: 'stopTime', visible: true, align: 'center', valign: 'middle'},
        {title: '耗时(分钟)', field: 'costTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
ScheduleStation.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ScheduleStation.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加车次线路管理
 */
ScheduleStation.openAddScheduleStation = function () {
    var index = layer.open({
        type: 2,
        title: '添加车次线路管理',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/scheduleStation/scheduleStation_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看车次线路管理详情
 */
ScheduleStation.openScheduleStationDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '车次线路管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/scheduleStation/scheduleStation_update/' + ScheduleStation.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除车次线路管理
 */
ScheduleStation.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/scheduleStation/delete", function (data) {
            Feng.success("删除成功!");
            ScheduleStation.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("scheduleStationId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询车次线路管理列表
 */
ScheduleStation.search = function () {
    var queryData = {};
    queryData['ticketRemainderId'] = $("#ticketRemainderId").val();
    ScheduleStation.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ScheduleStation.initColumn();
    var ticketRemainderId = $("#ticketRemainderId").val();
    var table = new BSTable(ScheduleStation.id, "/ticketRemainder/stationDetail/list/"+ticketRemainderId, defaultColunms);
    table.setPaginationType("client");
    ScheduleStation.table = table.init();
});
